#ifndef PRINCIPALWINDOW_HPP_INCLUDED
#define PRINCIPALWINDOW_HPP_INCLUDED

#include <gtkmm.h>
#include <libglademm.h>
#include <string>
#include "IRS.h"
#include "morphologypallet.hpp"
#include "conversionpallet.hpp"
#include "analysispallet.hpp"
#include "labellingpallet.hpp"
#include "objects.hpp"
#include "genericdatawindow.hpp"

class ImageWindow;
#include "imagewindow.hpp"

class MainWindow{
    Gtk::Window *principalwindow;
    Gtk::ImageMenuItem *menuopen;
    Gtk::ImageMenuItem *menuquit;
    Gtk::Button *morphology;
    Gtk::Button *conversion;
    Gtk::Button *analysis;
    Gtk::Button *labelling;
    Gtk::ToggleButton *resultwindow;
    Gtk::TreeView* imagetree;

    Gtk::Button *make_pre;
    Gtk::Button *make_label;
    Gtk::Button *make_contour;
    Gtk::Button *make_redo;

    Gtk::ComboBox *combo_structuretype;
    Gtk::SpinButton *spinbutton_image;
    Gtk::SpinButton *spinbutton_skel;
    Gtk::SpinButton *spinbutton_seeds;
    Gtk::SpinButton *spinbutton_body;
    Gtk::SpinButton *spinbutton_pointermap;
    Gtk::SpinButton *spinbutton_rcdata;
    Gtk::SpinButton *spinbutton_labelling;

    Gtk::SpinButton *sample_x;
    Gtk::SpinButton *sample_y;
    Gtk::SpinButton *radius1;
    Gtk::SpinButton *criticaldist;
    Gtk::SpinButton *superposition1;
    Gtk::SpinButton *superposition2;
    Gtk::SpinButton *acute;
    Gtk::SpinButton *opposite;
    Gtk::SpinButton *erosion;
    Gtk::SpinButton *areafilter;
    Gtk::SpinButton *stability;
    Gtk::SpinButton *prescale;


    bool new_windows;

    //Tree model columns:
    class ModelColumns : public Gtk::TreeModel::ColumnRecord
    {
        public:

        ModelColumns()
            { add(m_col_id); add(m_col_object); add(m_col_type);}
        Gtk::TreeModelColumn<unsigned int> m_col_id;
        Gtk::TreeModelColumn<Glib::ustring> m_col_object;
        Gtk::TreeModelColumn<Glib::ustring> m_col_type;
    };

    ModelColumns Columns;
    Glib::RefPtr<Gtk::ListStore> treeModel;


    public:
    MainWindow();

    //pallets
    MorphPallet *morphpallet;
    ConversionPallet *conversionpallet;
    AnalysisPallet *analysispallet;

    BranchLabellingOptions branchoptions;
    PreprocessingOption preoptions;

    list<Objects*> objectsopen;

    unsigned int emptyid;


    bool newwindow();
    void closethisObject(Objects* thisobject);
    Objects* getThisfromID(unsigned int ID);
    void updateimagetree();

    void forcercclassification(Position xy,CriticalRegion::RegionType type);

    //callbacks
    virtual void resultwindowchange();
    virtual void openImage();
    virtual void openMorphPallet();
    virtual void openConvPallet();
    virtual void openAnalysisPallet();
    virtual void changeparams();

    virtual void makepreprocessing();
    virtual void makelabelling();
    virtual void makecontour();
    virtual void redo();




    void invalidobjecterror();
    void invalidtypeerror();

    void outImage(Image* img);

};


#endif // PRINCIPALWINDOW_HPP_INCLUDED
